# Create your views here.
# -*- coding: utf-8 -*-
from django.http import HttpResponse, HttpResponseRedirect
from picture.models import Image as picture
from myblog.settings import *  
import Image  
import time
def addPicture(request):      
    reqfile = request.FILES['file']  
    print dir(request.FILES['file'])
    desc = request.POST['desc']
    image = Image.open(reqfile)  
    pic_name = time.time()
    path = "/site_media/pic/upload/" + str(pic_name) + ".jpeg"
    t_path = "/site_media/pic/upload/" + str(pic_name) + "_t.jpeg"
    image.save("./media/pic/upload/%s.jpeg"% pic_name) 
    image.thumbnail((100,100),Image.ANTIALIAS)
    image.save("./media/pic/upload/%s_t.jpeg" % pic_name, "jpeg") 
    pic = picture.objects.create(path = path, t_path = t_path, desc = desc)
    pic.save
    return HttpResponseRedirect('/photo/')
                